from django.db import models


class BookModel(models.Model):
    """
    创建图书表,
    作者与图书的关系是一对多
    图书与标签是多对多的关系
    """
    name = models.CharField(max_length=100, null=False, verbose_name='图书')
    price = models.FloatField(null=False, verbose_name='价格')
    author = models.ForeignKey('AuthorModel', on_delete=models.Case, verbose_name='作者')
    create_at = models.DateTimeField(auto_now_add=True, null=True, verbose_name='创建时间')
    update_at = models.DateTimeField(auto_now=True, null=True, verbose_name='更新时间')
    tags = models.ManyToManyField('TagModel')


class TagModel(models.Model):
    tag = models.CharField(max_length=100, null=False, verbose_name='标签')
    create_at = models.DateTimeField(auto_now_add=True, null=True, verbose_name='创建时间')
    update_at = models.DateTimeField(auto_now=True, null=True, verbose_name='更新时间')


class AuthorModel(models.Model):
    name = models.CharField(max_length=100, null=False, unique=True, verbose_name='作者名')
    create_at = models.DateTimeField(auto_now_add=True, null=True, verbose_name='创建时间')
    update_at = models.DateTimeField(auto_now=True, null=True, verbose_name='更新时间')
